{"ast":null,"code":"import _objectSpread from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/objectSpread2.js\";import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from'react';import{observer}from\"mobx-react-lite\";import{Context}from\"../../index\";import{findContactOrReturnNull}from\"../../utils/Contact\";import{Modal}from\"../index\";import'./ContactControl.scss';import{jsx as _jsx}from\"react/jsx-runtime\";import{jsxs as _jsxs}from\"react/jsx-runtime\";import{Fragment as _Fragment}from\"react/jsx-runtime\";var ContactControl=function ContactControl(props){var _React$useContext=React.useContext(Context),store=_React$useContext.store;var _React$useState=React.useState(),_React$useState2=_slicedToArray(_React$useState,2),findContactWithIndex=_React$useState2[0],setFindContactWithIndex=_React$useState2[1];var _React$useState3=React.useState(false),_React$useState4=_slicedToArray(_React$useState3,2),showModalPendingApplication=_React$useState4[0],setShowModalPendingApplication=_React$useState4[1];var _React$useState5=React.useState(false),_React$useState6=_slicedToArray(_React$useState5,2),showModalAlreadyContacts=_React$useState6[0],setShowModalAlreadyContacts=_React$useState6[1];React.useEffect(function(){if(!props.selfProfile&&store.getProfile().id!==props.profile.id){setFindContactWithIndex(_objectSpread(_objectSpread({},findContactWithIndex),findContactOrReturnNull(props.profile,store.getProfile(),store.getContacts())));}},[store.getContacts(),props.profile]);if(!props.selfProfile&&store.getProfile().id!==props.profile.id){if((findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.contact)===null){return/*#__PURE__*/_jsx(\"div\",{className:\"contact__control\",children:/*#__PURE__*/_jsx(\"button\",{className:\"contact__control-button-add\",onClick:function onClick(){return store.addContactFromAPI(props.profile.id);},children:\"\\u0414\\u043E\\u0431\\u0430\\u0432\\u0438\\u0442\\u044C \\u0432 \\u043A\\u043E\\u043D\\u0442\\u0430\\u043A\\u0442\\u044B\"})});}else if(findContactWithIndex!==null&&findContactWithIndex!==void 0&&findContactWithIndex.contact.status){return/*#__PURE__*/_jsxs(\"div\",{className:\"contact__control\",children:[/*#__PURE__*/_jsx(\"span\",{children:\"\\u0423 \\u0432\\u0430\\u0441 \\u0432 \\u043A\\u043E\\u043D\\u0442\\u0430\\u043A\\u0442\\u0430\\u0445\"}),/*#__PURE__*/_jsx(\"button\",{className:\"contact__control-button-delete\",onClick:function onClick(){setShowModalAlreadyContacts(true);},children:\"\\u0423\\u0434\\u0430\\u043B\\u0438\\u0442\\u044C \\u043A\\u043E\\u043D\\u0442\\u0430\\u043A\\u0442\"}),/*#__PURE__*/_jsx(Modal,{active:showModalAlreadyContacts,title:\"Удаление контакта\",hasFunctionButtons:true,onSubmit:function onSubmit(){store.deleteContactFromAPI(findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.contact,findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.index).then(function(){return setShowModalAlreadyContacts(false);});},onClose:function onClose(){return setShowModalAlreadyContacts(false);},customClassNameButtonSecond:\"messenger__sidebar-profileControl-deleteProfile\",children:/*#__PURE__*/_jsx(\"div\",{children:\"\\u0412\\u044B \\u0434\\u0435\\u0439\\u0441\\u0442\\u0432\\u0438\\u0442\\u0435\\u043B\\u044C\\u043D\\u043E \\u0445\\u043E\\u0442\\u0438\\u0442\\u0435 \\u0431\\u0435\\u0437\\u0432\\u043E\\u0437\\u0432\\u0440\\u0430\\u0442\\u043D\\u043E \\u0443\\u0434\\u0430\\u043B\\u0438\\u0442\\u044C \\u043A\\u043E\\u043D\\u0442\\u0430\\u043A\\u0442?\"})})]});}else{return/*#__PURE__*/_jsxs(\"div\",{className:\"contact__control\",children:[(findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.contact.fromUser.id)===store.getProfile().id&&/*#__PURE__*/_jsx(\"span\",{children:\"\\u0417\\u0430\\u044F\\u0432\\u043A\\u0430 \\u043E\\u0442\\u043F\\u0440\\u0430\\u0432\\u043B\\u0435\\u043D\\u0430\"}),(findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.contact.toUser.id)===store.getProfile().id&&/*#__PURE__*/_jsx(\"button\",{className:\"contact__control-button-accept\",onClick:function onClick(){return store.acceptContactFromAPI(findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.contact,findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.index);},children:\"\\u041F\\u0440\\u0438\\u043D\\u044F\\u0442\\u044C \\u0437\\u0430\\u044F\\u0432\\u043A\\u0443\"}),/*#__PURE__*/_jsx(\"button\",{className:\"contact__control-button-delete\",onClick:function onClick(){setShowModalPendingApplication(true);},children:\"\\u0423\\u0434\\u0430\\u043B\\u0438\\u0442\\u044C \\u0437\\u0430\\u044F\\u0432\\u043A\\u0443\"}),/*#__PURE__*/_jsx(Modal,{active:showModalPendingApplication,title:\"Удаление заявки\",hasFunctionButtons:true,onSubmit:function onSubmit(){store.deleteContactFromAPI(findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.contact,findContactWithIndex===null||findContactWithIndex===void 0?void 0:findContactWithIndex.index).then(function(){return setShowModalPendingApplication(false);});},onClose:function onClose(){return setShowModalPendingApplication(false);},customClassNameButtonSecond:\"messenger__sidebar-profileControl-deleteProfile\",children:/*#__PURE__*/_jsx(\"div\",{children:\"\\u0412\\u044B \\u0434\\u0435\\u0439\\u0441\\u0442\\u0432\\u0438\\u0442\\u0435\\u043B\\u044C\\u043D\\u043E \\u0445\\u043E\\u0442\\u0438\\u0442\\u0435 \\u0431\\u0435\\u0437\\u0432\\u043E\\u0437\\u0432\\u0440\\u0430\\u0442\\u043D\\u043E \\u0443\\u0434\\u0430\\u043B\\u0438\\u0442\\u044C \\u0437\\u0430\\u044F\\u0432\\u043A\\u0443?\"})})]});}}else{return/*#__PURE__*/_jsx(_Fragment,{});}};export default observer(ContactControl);","map":{"version":3,"names":["React","observer","Context","findContactOrReturnNull","Modal","ContactControl","props","useContext","store","useState","findContactWithIndex","setFindContactWithIndex","showModalPendingApplication","setShowModalPendingApplication","showModalAlreadyContacts","setShowModalAlreadyContacts","useEffect","selfProfile","getProfile","id","profile","getContacts","contact","addContactFromAPI","status","deleteContactFromAPI","index","then","fromUser","toUser","acceptContactFromAPI"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/components/ContactControl/index.tsx"],"sourcesContent":["import React from 'react';\nimport {observer} from \"mobx-react-lite\";\nimport {Context} from \"../../index\";\nimport {findContactOrReturnNull} from \"../../utils/Contact\";\nimport {UserProfileProps} from \"../../models/props/UserProfileProps\";\nimport {ContactWithIndex} from \"../../models/props/ContactWithIndex\";\nimport {Modal} from \"../index\";\nimport './ContactControl.scss';\n\nconst ContactControl: React.FC<UserProfileProps> = (props) => {\n    const {store} = React.useContext(Context);\n    const [findContactWithIndex, setFindContactWithIndex] = React.useState<ContactWithIndex>();\n    const [showModalPendingApplication, setShowModalPendingApplication] = React.useState<boolean>(false);\n    const [showModalAlreadyContacts, setShowModalAlreadyContacts] = React.useState<boolean>(false);\n\n    React.useEffect(() => {\n        if (!props.selfProfile && store.getProfile().id !== props.profile.id) {\n            setFindContactWithIndex({\n                ...findContactWithIndex,\n                ...findContactOrReturnNull(props.profile, store.getProfile(), store.getContacts())\n            });\n        }\n    }, [store.getContacts(), props.profile]);\n\n    if (!props.selfProfile &&\n        store.getProfile().id !== props.profile.id\n    ) {\n        if (findContactWithIndex?.contact === null) {\n            return (\n                <div className=\"contact__control\">\n                    <button\n                        className=\"contact__control-button-add\"\n                        onClick={() => store.addContactFromAPI(props.profile.id)}\n                    >Добавить в контакты</button>\n                </div>\n            );\n        } else if (findContactWithIndex?.contact.status) {\n            return (\n                <div className=\"contact__control\">\n                    <span>У вас в контактах</span>\n                    <button\n                        className=\"contact__control-button-delete\"\n                        onClick={() => {\n                            setShowModalAlreadyContacts(true);\n                        }}\n                    >Удалить контакт</button>\n                    <Modal\n                        active={showModalAlreadyContacts}\n                        title={\"Удаление контакта\"}\n                        hasFunctionButtons={true}\n                        onSubmit={() => {\n                            store.deleteContactFromAPI(findContactWithIndex?.contact!, findContactWithIndex?.index!).then(() =>\n                                setShowModalAlreadyContacts(false)\n                            );\n                        }}\n                        onClose={() => setShowModalAlreadyContacts(false)}\n                        customClassNameButtonSecond={\"messenger__sidebar-profileControl-deleteProfile\"}\n                    >\n                        <div>Вы действительно хотите безвозвратно удалить контакт?</div>\n                    </Modal>\n                </div>\n            );\n        } else {\n            return (\n                <div className=\"contact__control\">\n                    {findContactWithIndex?.contact.fromUser.id === store.getProfile().id &&\n                        <span>Заявка отправлена</span>\n                    }\n                    {findContactWithIndex?.contact.toUser.id === store.getProfile().id &&\n                        <button\n                            className=\"contact__control-button-accept\"\n                            onClick={() => store.acceptContactFromAPI(findContactWithIndex?.contact!, findContactWithIndex?.index!)}\n                        >Принять заявку</button>\n                    }\n                    <button\n                        className=\"contact__control-button-delete\"\n                        onClick={() => {\n                            setShowModalPendingApplication(true);\n                        }}\n                    >Удалить заявку</button>\n                    <Modal\n                        active={showModalPendingApplication}\n                        title={\"Удаление заявки\"}\n                        hasFunctionButtons={true}\n                        onSubmit={() => {\n                            store.deleteContactFromAPI(findContactWithIndex?.contact!, findContactWithIndex?.index!).then(() =>\n                                setShowModalPendingApplication(false)\n                            );\n                        }}\n                        onClose={() => setShowModalPendingApplication(false)}\n                        customClassNameButtonSecond={\"messenger__sidebar-profileControl-deleteProfile\"}\n                    >\n                        <div>Вы действительно хотите безвозвратно удалить заявку?</div>\n                    </Modal>\n                </div>\n            );\n        }\n    } else {\n        return (<></>);\n    }\n}\n\nexport default observer(ContactControl);"],"mappings":"2RAAA,MAAOA,MAAK,KAAM,OAAO,CACzB,OAAQC,QAAQ,KAAO,iBAAiB,CACxC,OAAQC,OAAO,KAAO,aAAa,CACnC,OAAQC,uBAAuB,KAAO,qBAAqB,CAG3D,OAAQC,KAAK,KAAO,UAAU,CAC9B,MAAO,uBAAuB,CAAC,6IAE/B,GAAMC,eAA0C,CAAG,QAA7CA,eAA0C,CAAIC,KAAK,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